<template>
  <div style="position: relative;width: 162px;">
    <el-input
      v-model="info_mat_no"
      type="input"
      placeholder="请输入内容"
      class="xw_inputPreNext"
      style="width: 174px;position: absolute;top: 3px;">
      <!--@keyup.enter.native="search"
      -->>
      <template slot="prepend">
        <div class="xw_divBtn">
          <el-button
            type="primary"
            @click="preNext(1)"><i class="el-icon-caret-left"/> </el-button>
        </div>
      </template>
      <template slot="append">
        <div class="xw_divBtn">
          <el-button
            type="primary"
            @click="preNext(-1)"><i class="el-icon-caret-right"/> </el-button>
        </div>
      </template>
    </el-input>
  </div>
</template>

<script>
import { post } from '@/lib/Util'
export default {
  name: 'Coil',
  props: {
    matNo: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      info_mat_no: '',
      countType: 0,
      matNoAll: [],
      matNoLine: {}
    }
  },
  watch: {
    matNo: {
      handler(newVal, oldVal) {
        // this.search(this.matNo)
        this.info_mat_no = this.matNo
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {
    this.getNewMatNo(true)
  },
  methods: {
    // 工艺详情获取卷号
    getMatNo() {
      return this.info_mat_no
    },
    // 工艺详情获取产线
    getMatNoLine() {
      let cal_no = ''
      for (var i in this.matNoAll) {
        if (this.matNoAll[i].coil_no_out === this.info_mat_no) {
          cal_no = this.matNoAll[i].cal_no
        }
      }
      return cal_no
    },
    search(params) {
      // 搜索条件改变时
      console.log('查询条件', params)
      this.$emit('search', this.info_mat_no)
    },
    async getNewMatNo(flag) {
      const res = await post(this.urlApi.mppCalgetNewCoilId, {})
      this.matNoAll = res
      this.countType = 0
      if (this.info_mat_no === '') {
        this.info_mat_no = this.matNoAll[this.countType].coil_no_out
      }
      if (flag) {
        this.$emit('search', this.info_mat_no)
      }
    },
    // 查询上一卷下一卷
    async preNext(type) {
      this.countType += type
      if (this.countType < 0) {
        this.getNewMatNo(false)
      } else {
        this.info_mat_no = this.matNoAll[this.countType].coil_no_out
        this.search(this.info_mat_no)
      }
    }
  }
}
</script>

<style scoped>
/deep/.el-input-group__append {
  padding: 0px;
}
/deep/.el-input-group__prepend {
  padding: 0px;
}
/deep/.el-input__inner {
  padding: 2px 0px !important;
}
</style>
<style>
.xw_inputPreNext .xw_divBtn {
  width: 21px;
}
</style>
